package ctgu.junitTest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

import ctgu.java.HoldingTimeByZoned;

class HoldingTimeByZonedTest {

    @Test
    @Order(1)
    @DisplayName("开始通话和结束通话时间均在标准时间内,且通话为整数分钟")
    void testBetweenStandardTime() {
        
        LocalDateTime startingTime = 
            LocalDateTime.of(2021,2,3,12,30,0);
        ZonedDateTime zonedStartTime = 
            startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = 
            LocalDateTime.of(2021, 2,3,12,50,0);
        ZonedDateTime zonedEndTime = 
            endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(20, holdingTime.getHoldingTime());
    }
    
    @Test
    @Order(2)
    @DisplayName("开始通话和结束通话时间均在标准时间内,且通话不为整数分钟")
    void testBetweenStandardTime_with_seconds() {
        
        LocalDateTime startingTime = 
            LocalDateTime.of(2021,2,3,12,30,0);
        ZonedDateTime zonedStartTime = 
            startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = 
            LocalDateTime.of(2021, 2,3,12,50,25);
        ZonedDateTime zonedEndTime = 
            endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(21, holdingTime.getHoldingTime());
    }
    
    @Test
    @Order(3)
    @DisplayName("开始通话在标准时间，结束通话时间在夏令时内,且通话为整数分钟")
    void testBetweenDaylightTime() {
        
        LocalDateTime startingTime =
            LocalDateTime.of(2021,3,14,1,20,0);
        ZonedDateTime zonedStartTime = 
            startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = 
            LocalDateTime.of(2021,3,14,3,20,0);
        ZonedDateTime zonedEndTime = endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(60, holdingTime.getHoldingTime());
    }
    
    @Test
    @Order(4)
    @DisplayName("开始通话在标准时间，结束通话时间在夏令时内,且通话不为整数分钟")
    void test_standard_to_DaylightTime() {
        
        LocalDateTime startingTime = LocalDateTime.of(2021,3,14,1,20,30);
        ZonedDateTime zonedStartTime = startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = LocalDateTime.of(2021,3,14,3,20,0);
        ZonedDateTime zonedEndTime = endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(60, holdingTime.getHoldingTime());
    }  
    
    @Test
    @Order(5)
    @DisplayName("开始通话在夏令营，结束通话时间在标准时间内,且通话为整数分钟")
    void test_DaylightTime_to_standard() {
        
        LocalDateTime startingTime = LocalDateTime.of(2021,11,7,1,20,0);
        ZonedDateTime zonedStartTime = startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = LocalDateTime.of(2021,11,7,2,20,0);
        ZonedDateTime zonedEndTime = endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(120, holdingTime.getHoldingTime());
    }  
    
    @Test
    @Order(6)
    @DisplayName("开始通话在夏令营，结束通话时间在标准时间内,且通话不为整数分钟")
    void test_DaylightTime_to_standard2() {
        
        LocalDateTime startingTime = LocalDateTime.of(2021,11,7,1,20,0);
        ZonedDateTime zonedStartTime = startingTime.atZone(ZoneId.of("America/New_York"));
        
        LocalDateTime endingTime = LocalDateTime.of(2021,11,7,2,20,45);
        ZonedDateTime zonedEndTime = endingTime.atZone(ZoneId.of("America/New_York"));
        
        HoldingTimeByZoned holdingTime = new HoldingTimeByZoned(zonedStartTime, zonedEndTime);
        
        assertEquals(121, holdingTime.getHoldingTime());
    }  
}